
/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#jixiao-chaxun").trigger('click'); 
		return false;
		}
	});
});

var KSSJ = '';
var JSSJ = '';
var ISKUCUNPC = false;
var ONLYTONGJI = false;
//从jsp页面获取时间
function getShijian(mrkaishisj,mrjieshusj,isguanliyuan,iskucunpc,onlytongji){
	//刚进入页面时加载员工绩效数据
	var xiangmumc = $('#ygjx-xiangmumc').val();
	var kaishisj = mrkaishisj;
	var jieshusj = mrjieshusj;
	KSSJ = mrkaishisj;
	JSSJ = mrjieshusj;
	ISKUCUNPC = iskucunpc;
	ONLYTONGJI = onlytongji;
	$('#ygjx-kaishjsj').val(kaishisj);
	$('#ygjx-jieshusj').val(jieshusj);
	var xiangmufl = 0;
	if(onlytongji){
		return false;
	}
	if(isguanliyuan){
		chaxun(xiangmumc,kaishisj,jieshusj,xiangmufl);
		//获得员工
		getyuangong();
	}else{
		var yuangong = $('.dropdown-toggle').text();
		chaxungerenjx(xiangmumc,kaishisj,jieshusj,xiangmufl,yuangong)
	}
}

/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#chaxtj-fjflb-chaxunbtn").trigger('click'); 
		return false;
		}
	});
});

//下拉匡取值
$(document).on('click','#cxygjx-list-title .dropdown-menu li',function(){
	var bText = $(this).text();
    var bValue = $(this).val();
    $(this).parent().siblings(".dropdown-toggle").html(bText+"<b></b>");
    $(this).parent().siblings(".dropdown-toggle").val(bValue);
    $(this).parent().css("display","none");
    //显示的列表是员工个人还是全部
    if(!!bValue){
    	$('#jixiao-quanbuyg').css('display','none');
    	$('#jixiao-dangeyg').css('display','block');
    }else{
    	$('#jixiao-quanbuyg').css('display','block');
    	$('#jixiao-dangeyg').css('display','none');
    }
    find();
});

//查找的方法
function find(){
	$('#zongrenci').text('0人次');
	$('#zongshouru').text('0.00元');
	$('#zonglilun').text('0.00元');
	var val = $('.dropdown-toggle').val();
	var xiangmumc = $('#ygjx-xiangmumc').val();
	var kaishisj = $('#ygjx-kaishjsj').val();
	var jieshusj = $('#ygjx-jieshusj').val();
	var xiangmufl = $('.xuanzong').val();
	var yuangong = $('.dropdown-toggle').text();
	if(!(yuangong == '全部')){
		chaxungerenjx(xiangmumc,kaishisj,jieshusj,xiangmufl,yuangong)
	}else{
		chaxun(xiangmumc,kaishisj,jieshusj,xiangmufl);
	}
}

//点击项目分类中的li标签
$('#xiangmufl-ul li').click(function(){
	$(this).parent().children().removeClass('xuanzong');
	if(!$(this).hasClass('xuanzong')){
		$(this).addClass('xuanzong');
	}
	find();
});

//点击选取日期时
$('#ygjx-kaishjsj').blur(function(){
	find();
});

$('#ygjx-jieshusj').blur(function(){
	find();
});

//点击查询按钮
$('#jixiao-chaxun').click(function(){
	find();
});

//点击重置按钮
$('#jixiao-chongzhi').click(function(){
		$('#ygjx-xiangmumc').val('');
		$('#ygjx-kaishjsj').val(KSSJ);
		$('#ygjx-jieshusj').val(JSSJ);
		if(!(ONLYTONGJI == true)){
			$('#yuangong-div').html("全部<b></b>");
			$('#jixiao-quanbuyg').css('display','block');
			$('#jixiao-dangeyg').css('display','none');
		}
		$('.xuanzong').removeClass('xuanzong');
		$('#xiangmufl-ul li:first').addClass('xuanzong');
		find();
});

//查询所有员工绩效函数
function chaxun(xiangmumc,kaishisj,jieshusj,xiangmufl){
	if(ONLYTONGJI){
		return false;
	}
	var totalNumber = 0;
	$('#tb-chaxtjygjxmx1').html('');
	var msg = {
			"xiangmumc": xiangmumc,
			"kaishisj": kaishisj,
			"jieshusj": jieshusj,
			"xiangmufl": xiangmufl
	};
	$.ajax({
		url: path + '/jixiao/getJixiaoCount',
		type: 'post',
		data: msg,
		async: false,
		success: function(data){
			if(data!=null) {
	    		totalNumber = data;
			}
	    	if(totalNumber==0){
				$(".list-content").css("display","none");
				$("#chaxtj-ygjx-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
			}else{
				$(".list-content").css("display","block");
				$("#chaxtj-ygjx-img").html("");
			}
		}
	});
	
	var container = $('#pagination-fenygojxmx1');
  	container.pagination({
    dataSource:path + '/jixiao/getJixiao?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&xiangmumc='+xiangmumc+'&xiangmufl='+xiangmufl,
    locator: '',
    pageSize: 12,
	showNavigator: true,
    formatNavigator: '共 <%= totalNumber %> 条',
    totalNumber: totalNumber,
    callback: function (data, pagination) {
  		if(!!data){
  			var content = '';
			$(data).each(function(index,e){
				var xingming = this.xingming;
				var jiuzhenrc = this.jiuzhenrc;
				var shouru = this.shouru;
				var lilun = this.lilun;
				if(shouru == null){
					shouru = '';
				}else{
					shouru = shouru.toFixed(2);
				}
				if(lilun == null){
					lilun = '';
				}else{
					lilun = lilun.toFixed(2);
				}
				index = ((pagination.pageNumber-1)*pagination.pageSize)+index+1;
				content += '<tr>'+
				'<td >' + index + '</td>'+
                '<td >' + xingming + '</td>'+
                '<td >' + jiuzhenrc + '</td>'+
                '<td >' + shouru + '</td>';
                if(ISKUCUNPC){
                	content +=	'<td >' + lilun + '</td>';
                }else{
                	$("#jixiao-dangeyg  thead .a-yuangong-lirun").remove();
                	$("#jixiao-quanbuyg  thead .a-yuangong-lirun").remove();
                }
                
				content += '</tr>';
			});
			$.ajax({
				url: path + '/jixiao/getQuanbuygzong',
				type: 'post',
				data: msg,
				async: false,
				success: function(data){
					var zongrenci = '';
					var zongshouru = '';
					var zonglilun = '';
					if(data.zongrenci == null){
						zongrenci = 0;
					}else{
						zongrenci = data.zongrenci;
					}
					if(data.zongshouru == null){
						zongshouru = 0;
					}else{
						zongshouru = data.zongshouru;
					}
					if(data.zonglilun == null){
						zonglilun = 0;
					}else{
						zonglilun = data.zonglilun;
					}
					$('#zongrenci').text(zongrenci+'人次');
					$('#zongshouru').text(zongshouru.toFixed(2)+'元');
					$('#zonglilun').text(zonglilun.toFixed(2)+'元');
				}
			});

			$('#tb-chaxtjygjxmx1').html(content);
  		}
  	}
  	});
	if(totalNumber <= 12) {
		$('#pagination-fenygojxmx1').css('display','none');
	}else{
		$('#pagination-fenygojxmx1').css('display','block');
	}
}

//查询员工函数
function getyuangong(){
	$('#jixiao-yuangong').html('');
	var str = '<li value="0">全部</li>';
	$.ajax({
		url: '../jixiao/getYuangong',
		type: 'post',
		success: function(data){
			$(data).each(function(index,e){
				str += '<li value="' + index+1 + '">' + e + '</li>';
			});
			$('#jixiao-yuangong').html(str);
		}
	});
}

//查询员工个人绩效函数
function chaxungerenjx(xiangmumc,kaishisj,jieshusj,xiangmufl,yuangong){
	if(ONLYTONGJI){
		return false;
	}
	var totalNumber = 0;
	var msg = {
			"xiangmumc": xiangmumc,
			"kaishisj": kaishisj,
			"jieshusj": jieshusj,
			"xiangmufl": xiangmufl,
			"yuangongxm": yuangong
	}
	$('#tb-chaxtjygjxmx2').html('');
	$.ajax({
		url: path + '/jixiao/getGerenJixiaoCount',
		type: 'post',
		data: msg,
		async: false,
		success: function(data){
			if(data!=null) {
	    		totalNumber = data;
			}
	    	if(totalNumber==0){
				$(".list-content").css("display","none");
				$("#chaxtj-ygjx-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
			}else{
				$(".list-content").css("display","block");
				$("#chaxtj-ygjx-img").html("");
			}
		}
	});
	var container = $('#pagination-fenygojxmx2');
  	container.pagination({
    dataSource:path + '/jixiao/getGerenJixiao?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&xiangmumc='+xiangmumc+'&xiangmufl='+xiangmufl+'&yuangongxm='+yuangong,
    locator: '',
    pageSize: 12,
	showNavigator: true,
    formatNavigator: '共 <%= totalNumber %> 条',
    totalNumber: totalNumber,
    callback: function (data, pagination) {
  		if(!!data){
  			var content = '';
			$(data).each(function(index,e){
				var mingcheng = this.mingcheng;
				var chuangjiansj = this.chuangjiansj;
				var xiangmulx = '';
				switch(this.xiangmulx){
					case 1: xiangmulx = '成药';break;
					case 2: xiangmulx = '草药';break;
					case 3: xiangmulx = '检查项';break;
					case 4: xiangmulx = '附加费';break;
					case 5: xiangmulx = '耗材';break;
				}
				var zhehouje = this.zhehouje;
				var lilun = this.lilun;
				if(zhehouje == null){
					zhehouje = '';
				}else{
					zongshouru += zhehouje;
					zhehouje = zhehouje.toFixed(2);
				}
				if(lilun == null){
					lilun = '';
				}else{
					zonglilun += lilun;
					lilun = lilun.toFixed(2);
				}
				index = ((pagination.pageNumber-1)*pagination.pageSize)+index+1;
				content += '<tr>'+
				'<td >' + index + '</td>'+
                '<td >' + chuangjiansj + '</td>'+
                '<td >' + xiangmulx + '</td>'+
                '<td >' + mingcheng + '</td>'+
                '<td >' + this.xiaoshoujia.toFixed(2) || '' + '</td>';
                if(ISKUCUNPC){
                	content +=	'<td >' + lilun + '</td>';
                }else{
                	$("#jixiao-dangeyg  thead .a-yuangong-lirun").remove();
                	$("#jixiao-quanbuyg  thead .a-yuangong-lirun").remove();
                }
                
				content += '</tr>';
			});
			$.ajax({
				url: path + '/jixiao/getGerenygzong',
				type: 'post',
				data: msg,
				async: false,
				success: function(data){
					var zongrenci = '';
					var zongshouru = '';
					var zonglilun = '';
					if(data.zongrenci == null){
						zongrenci = 0;
					}else{
						zongrenci = data.zongrenci;
					}
					if(data.zongshouru == null){
						zongshouru = 0;
					}else{
						zongshouru = data.zongshouru;
					}
					if(data.zonglilun == null){
						zonglilun = 0;
					}else{
						zonglilun = data.zonglilun;
					}
					$('#zongrenci').text(zongrenci+'人次');
					$('#zongshouru').text(zongshouru.toFixed(2)+'元');
					$('#zonglilun').text(zonglilun.toFixed(2)+'元');
				}
			});
			
			$('#tb-chaxtjygjxmx2').html(content);
  		}else{
  			
  		}
  	}
  	});
	if(totalNumber <= 12) {
		$('#pagination-fenygojxmx2').css('display','none');
	}else{
		$('#pagination-fenygojxmx2').css('display','block');
	}
	
}





